package com.kuzufang.modules.main.room;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.SpannableString;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

import com.cunoraz.tagview.Tag;
import com.cunoraz.tagview.TagView;
import com.kuzufang.R;
import com.kuzufang.base.BaseActivity;
import com.kuzufang.modules.main.roommate.RoomConfigurationAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by songyuanjin on 2017/9/28.
 */

public class FindRoomDetailActivity extends BaseActivity {
    private Toolbar mToolBar;
    private RecyclerView mRoomConfigRecyclerView;
    private RoomConfigurationAdapter roomConfigAdapter;
    private TextView tvSubwayStation;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_find_room_detail);

        mToolBar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(mToolBar);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        mToolBar.setTitle("");

        initTag2();

        mRoomConfigRecyclerView = (RecyclerView) findViewById(R.id.room_recycler_view);
        roomConfigAdapter = new RoomConfigurationAdapter(this);
        mRoomConfigRecyclerView.setLayoutManager(new GridLayoutManager(this, 4));
        mRoomConfigRecyclerView.setAdapter(roomConfigAdapter);
        mRoomConfigRecyclerView.setFocusable(false);

        tvSubwayStation = (TextView) findViewById(R.id.tv_subway_station);

        String line1 = "2号线 南京西路";
        String line2 = "10号线 南京东路";
        SpannableString spannableString = new SpannableString(line1 + "、" + line2);
        // spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#8EC447")), 0, line1.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        // spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#BEAAD3")), line1.length() + 1, line1.length() + line2.length() + 1, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        tvSubwayStation.setText(spannableString);

    }

    private void initTag2() {
        List<String> stringList = new ArrayList<>();
        stringList.add("运动");
        stringList.add("拒绝晚睡");
        stringList.add("禁止抽烟");
        final TagView tagGroup = (TagView) findViewById(R.id.tag_user_info_group);
        final List<Tag> tags = new ArrayList<>();
        for (int i = 0; i < stringList.size(); i++) {
            Tag tag = new Tag(stringList.get(i));
            tag.layoutColor = Color.parseColor("#FFFFFF");
            tag.tagTextColor = Color.parseColor("#009688");
            tag.tagTextSize = 12.0f;
            tag.radius = 80.0f;
            tag.layoutBorderSize = 1;
            tag.layoutBorderColor = Color.parseColor("#009688");
            tags.add(tag);
        }
        tagGroup.addTags(tags);

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                onBackPressed();
                return true;
            case R.id.share:
                Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
                sharingIntent.setType("text/plain");
                String shareBodyText = "Check it out. Your message goes here";
                sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject here");
                sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBodyText);
                startActivity(Intent.createChooser(sharingIntent, "Shearing Option"));
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.detail_right_menu, menu);
        return true;
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }
}
